package com.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.entity.Response;
import com.entity.pojo.LfRecruitment;
import com.service.RecruitmentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/recruitment")
public class RecruitmentController {

    @Resource
    private RecruitmentService recruitmentService;

    @PostMapping
    public Response insertRecruitment(@RequestBody LfRecruitment recruitment) {
        int re = recruitmentService.addRecruitment(recruitment);
        if (re > 0) {
            return new Response().setSuccess();
        } else {
            return new Response().setFailed().setErrMsg("新增失败");
        }
    }

    @GetMapping
    public Response listRecruitment() {
        List<LfRecruitment> lfRecruitments = recruitmentService.listRecruitment();
        return new Response().setSuccess().appendMsg("list", lfRecruitments);
    }

    @DeleteMapping
    public Response deleteRecruitment(@RequestParam("id") Integer id) {
        int re = recruitmentService.deleteOne(id);
        if (re > 0) {
            return new Response().setSuccess();
        } else {
            return new Response().setFailed().setErrMsg("操作失败");
        }
    }
}
